package com.kyubi.tagger.taggers;

import java.util.Vector;

import com.kyubi.common.data.Instances;
import com.kyubi.common.data.XMLToInstanceConvertor;
import com.kyubi.tagger.ITagger;

/**
 * A class representing the base decorator which deals with reading the XML data file.
 * This class just echos the lines read from the file. 
 * 
 * @author anand
 *
 */
public class XMLWrapper implements ITagger {

	private String filePath = null;
	private Vector<String> data = null;

	/**
	 * 
	 * @param filePath the xml file
	 */
	public XMLWrapper(String filePath) {
		this.filePath = filePath;
	}
	
	/**
	 * Function to reset the xml file path
	 * @param newFilePath	the new xml file path
	 */
	public void setFilePath(String newFilePath){
		this.filePath = newFilePath;
	}
	
	/**
	 * 
	 * @param insts	Instances object
	 */
	public XMLWrapper(Instances insts) {
		this.data = insts.getData();
	}

	/**
	 * @see com.kyubi.tagger.ITagger
	 */
	public Vector<String> getTaggedValues() {

		if (filePath != null) {
			try {
				XMLToInstanceConvertor xmlToInstConv = new XMLToInstanceConvertor(
						filePath);
				Instances insts = xmlToInstConv.convert();

				data = insts.getData();
			} catch (Exception e) {
				e.printStackTrace();
				return null;
			}
		}
		
		return data;
	}

	/**
	 * @see com.kyubi.tagger.ITagger
	 */
	public Vector<String> getOriginalValues() {
		Vector<String> dataVect = new Vector<String>(data);
		return dataVect;
	}
}
